﻿using ChestPainCenterSystem.Bll;
using ChestPainCenterSystem.Core;
using ChestPainCenterSystem.Model;
using ChestPainCenterSystem.ThreeCenterManage;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Common;
using ChestPainCenterSystem.Code.Bll;
using ChestPainCenterSystem.Utils;
using System.Configuration;
using SQLDLL;

namespace ChestPainCenterSystem.Areas.ChestPainCenter.Controllers
{
    public class MedicalRecordsController : BaseController
    {
        // GET: /ChestPainCenter/MedicalRecords/
        [ValidateInput(false)]
        public ActionResult Index()
        {
            string patientId = WebUtils.GetString("patientId");
            ViewBag.patientId = patientId;
            GetDropRoomList();
            GetDropDocNurList();
            GetDropDoctorList();
            GetDropNurseList();
            return View();
        }

        /// <summary>
        /// 获取胸痛病历
        /// </summary>
        /// <param name="patientId"></param>
        /// <returns></returns>
        public ActionResult GetCaseHistory(string Pid)
        {
            OperateResult resultInfo = MedicalRecordsManager.GetCaseHistory(Pid);
            return JsonDate(resultInfo);
        }

        /// <summary>
        /// 获取诊断路径列表
        /// </summary>
        /// <returns></returns>
        public ActionResult GetPathNameList()
        {
            OperateResult resultInfo = PathwayManager.GetPathNameList();
            return JsonDate(resultInfo);
        }

        /// <summary>
        /// 根据诊疗路径ID获取模板或内容
        /// </summary>
        /// <param name="pathId"></param>
        /// <returns></returns>
        public ActionResult GetDiagnosticPathTemp(int pathId, string patientId)
        {
            OperateResult resultInfo = PathwayManager.GetDiagnosticPathTemp(pathId, patientId);
            return JsonDate(resultInfo);
        }

        /// <summary>
        /// 获取初步诊断信息
        /// </summary>
        /// <param name="patientId"></param>
        /// <returns></returns>
        public ActionResult GetPatientIDPrimaryDiagnosis(string patientId)
        {
            OperateResult resultInfo = PathwayManager.GetPatientIDPrimaryDiagnosis(patientId);
            return JsonDate(resultInfo);
        }

        /// <summary>
        /// 修改胸痛病历
        /// </summary>
        /// <param name="patientId"></param>
        /// <returns></returns>
        [ValidateInput(false)]
        public ActionResult SetCaseHistory(string ContentList)
        {
            string pid = Request["pidd"];
            OperateResult resultInfo = MedicalRecordsManager.GetCaseHistory(pid);
            string json = resultInfo.Body.ToString();
            SetCaseHistory PatHis = JsonConvert.DeserializeObject<SetCaseHistory>(json);
            if (PatHis == null) return Content("病历不存在");
            //获取三张图片原文件名
            string Image1_ADD_Old = PatHis.Image1_ADD;
            string Image2_ADD_Old = PatHis.Image2_ADD;
            string Image_ADD_Old = PatHis.Image_ADD;
            PatHis.PatientName = Request["txtName"].ToString();
            PatHis.PatientSex = Request.Form["selSex"] ?? "-1";
            PatHis.PatientAge = Request.Form["txtAge"].ToString();
            PatHis.PatientPhone = Request.Form["txtPhone"].ToString();
            PatHis.PatientId = Request.Form["txtID"].ToString();
            PatHis.PatientIdNum = Request.Form["txtCardID"].ToString();
            PatHis.PatientAddr = Request.Form["txtAddress"].ToString();
            PatHis.EmsDiseaseTime = Request.Form["dtDiseaseTime"].ToIsNULLDateTime1(0);
            PatHis.EMS_DISEASE_ADDR = Request.Form["txtillAddress"].ToString();
            PatHis.ConditionAssessment = Request.Form["illestimateList"].ToIsNULLString();
            PatHis.PatientArriveClass = Request["eventGrade"].ToString();
            PatHis.CarType = string.IsNullOrEmpty(Request["CarType"]) ? 0 : Convert.ToInt32(Request["CarType"]);
            PatHis.DoctorArriveTime = Request["txtDoctorArriveTime"].ToIsNULLDateTime1(0);
            PatHis.TransferOutHospital = Request["txtTransferOutHospital"];
            PatHis.ArriveDoorTime = Request["txtArriveDoorTime"].ToIsNULLDateTime1(0);
            PatHis.SureTransferOutTime = Request["txtSureTransferOutTime"].ToIsNULLDateTime1(0);
            PatHis.AmbulanceArriveTime = Request["txtAmbulanceArriveTime"];
            PatHis.LeaveTime = Request["txtLeaveTime"].ToIsNULLDateTime1(0);
            PatHis.DiseaseDep = Request["txtDiseaseDep"];
            PatHis.ConsultationTime = Request["txtConsultationTime"].ToIsNULLDateTime1(0);
            PatHis.LeaveDepTime = Request["txtLeaveDepRoomTime"].ToIsNULLDateTime1(0);
            PatHis.EmsArriveDoorTime = Request.Form["txtArriveTime"].ToIsNULLDateTime1(0);
            PatHis.HMedicalTime = Request.Form["txtReceiveTime"].ToIsNULLDateTime1(0);
            PatHis.IsRound = Request.QueryString["Bypass"].ToString();
            PatHis.ThroughToTime = Request.Form["txtArriveBypass"].ToIsNULLDateTime1(0);
            PatHis.ThroughToDep = Request["txthdnArriveKRoom"].ToString();
            PatHis.ThroughToTime = PatHis.ThroughToTime == null ? Request.Form["txtArriveDirect"].ToIsNULLDateTime1(0) : PatHis.ThroughToTime;
            PatHis.AMFirst_Institutions = Request.QueryString["FirstT"].ToString();
            PatHis.AMMedical_Name = Request.Form["txtNurse"].ToString();
            PatHis.AMBULANCE_Contact_Time = Request["txtFirstECGTime"].ToIsNULLDateTime1(0);
            //PatHis.PRE_ECG_TIME = Request["txtYqxdtTime"].ToIsNULLDateTime1(0);
            PatHis.AMEcg_Time = Request["txtYqxdtTime"].ToIsNULLDateTime1(0);
            PatHis.Delivery_Time = Request["txtDelivery_Time1"].ToIsNULLDateTime1(0);
            PatHis.Aspirin = Request["txtmgAspirin"].ToIsNULLDouble();
            if (PatHis.Aspirin == 0) PatHis.Aspirin = null;
            PatHis.Ticagrelor = Request["txtmgTicagrelor"].ToIsNULLDouble();
            if (PatHis.Ticagrelor == 0) PatHis.Ticagrelor = null;
            PatHis.Clopidogrel = Request["txtmgClopidogrel"].ToIsNULLDouble();
            if (PatHis.Clopidogrel == 0) PatHis.Clopidogrel = null;
            PatHis.Rosuvastatin = Request["txtmgRosuvastatin"].ToIsNULLDouble();
            if (PatHis.Rosuvastatin == 0) PatHis.Rosuvastatin = null;
            PatHis.Atorvastatin = Request["txtmgAtorvastatin"].ToIsNULLDouble();
            if (PatHis.Atorvastatin == 0) PatHis.Atorvastatin = null;
            PatHis.Heparin = Request["txtmgHeparin"].ToIsNULLDouble();
            if (PatHis.Heparin == 0) PatHis.Heparin = null;
            PatHis.Catheter_Ecg_Time = Request["txtCatheter_Ecg_Time"].ToIsNULLDateTime1(0);
            PatHis.Troponin_Blood_Time = Request["txtTroponin_Blood_Time"].ToIsNULLDateTime1(0);
            PatHis.First_Institutions = Request["FirstT2"];
            PatHis.Medical_Name = Request["txtMedical_Name"];
            PatHis.Contact_Time = Request["txtContact_Time"].ToIsNULLDateTime1(0);
            PatHis.Ecg_Confirmed_Time = Request["txtEcg_Confirmed_Time"].ToIsNULLDateTime1(0);
            PatHis.EcgConfirmTime = Request["txtECG_CONFIRM_TIME"].ToIsNULLDateTime1(0);
            PatHis.FirstDiagnosisTime = Request["txtFirstDiagnosisTime"].ToIsNULLDateTime1(0);
            PatHis.RoomMeetTime = Request["txtRoomMeetTime"].ToIsNULLDateTime1(0);
            PatHis.MeetRoomName = Request["txtMeetRoomName"];
            PatHis.DeliveryTime = Request["txtDelivery_Time2"].ToIsNULLDateTime1(0);
            PatHis.AspirinYn = Request["txtmgAspirin2"].ToIsNULLDouble();
            if (PatHis.AspirinYn == 0) PatHis.AspirinYn = null;
            PatHis.TicagrelorYn = Request["txtmgTicagrelor2"].ToIsNULLDouble();
            if (PatHis.TicagrelorYn == 0) PatHis.TicagrelorYn = null;
            PatHis.ClopidogrelYn = Request["txtmgClopidogrel2"].ToIsNULLDouble();
            if (PatHis.ClopidogrelYn == 0) PatHis.ClopidogrelYn = null;
            PatHis.RosuvastatinYn = Request["txtmgRosuvastatin2"].ToIsNULLDouble();
            if (PatHis.RosuvastatinYn == 0) PatHis.RosuvastatinYn = null;
            PatHis.AtorvastatinYn = Request["txtmgAtorvastatin2"].ToIsNULLDouble();
            if (PatHis.AtorvastatinYn == 0) PatHis.AtorvastatinYn = null;
            PatHis.LeaveRoomTime = Request["txtLeaveRoomTime"].ToIsNULLDateTime1(0);
            PatHis.DeterminCatheterTime = Request["txtDeterminCatheterTime"].ToIsNULLDateTime1(0);
            PatHis.StartinforConsentTime = Request["txtStartinforConsentTime"].ToIsNULLDateTime1(0);
            PatHis.SigninforConsentTime = Request["txtSigninforConsentTime"].ToIsNULLDateTime1(0);
            PatHis.Enzyme = Request["txtEnzyme"].ToIsNULLInt(0);
            PatHis.Urokinase = Request["txtUrokinase"].ToIsNULLInt(0);
            PatHis.GuessD2BMins = Request["txtGuessD2BMins"].ToIsNULLInt(0).ToString();

            PatHis.Ecg_Time = Request["txtEcg_Time"].ToIsNULLDateTime1(0);
            PatHis.FirstHEcgTime = Request.Form["txtFirstECGTime"].ToIsNULLDateTime1(0);
            PatHis.Doubt_Radiology_NoticeTime = Request.Form["txtDoubt_Radiology_NoticeTime"].ToIsNULLDateTime1(0);
            PatHis.Doubt_Radiology_ArriveTime = Request.Form["txtDoubt_Radiology_ArriveTime"].ToIsNULLDateTime1(0);
            PatHis.Doubt_Radiography_Time = Request.Form["txtDoubt_Radiography_Time"].ToIsNULLDateTime1(0);
            PatHis.Doubt_Radiography_DIAGNOSISTime = Request.Form["txtDoubt_Radiography_DIAGNOSISTime"].ToIsNULLDateTime1(0);
            PatHis.Doubt_Radiography_DIAGNOSIS = Request.Form["Doubt_Radiography_DIAGNOSIS"];
            //三组图片
            string dirUrl = Request.Url.AbsoluteUri.ToLower();
            dirUrl = dirUrl.StartsWith("https") ? "https://" : "http://";
            dirUrl = dirUrl + Request.ServerVariables["HTTP_HOST"] + Base.ImageUploadPath;

            //string txtImage11_ADD = Request["txtfile11pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage11_ADD"];
            //string txtImage12_ADD = Request["txtfile12pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage12_ADD"];
            //string txtImage13_ADD = Request["txtfile13pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage13_ADD"];
            //string txtImage14_ADD = Request["txtfile14pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage14_ADD"];
            //string txtImage15_ADD = Request["txtfile15pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage15_ADD"];
            //string txtImage16_ADD = Request["txtfile16pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage16_ADD"];
            //string txtImage17_ADD = Request["txtfile17pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage17_ADD"];
            //string txtImage18_ADD = Request["txtfile18pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage18_ADD"];
            //PatHis.Image1_ADD = txtImage11_ADD + "#" + txtImage12_ADD + "#" + txtImage13_ADD + "#" + txtImage14_ADD + "#" +
            //    txtImage15_ADD + "#" + txtImage16_ADD + "#" + txtImage17_ADD + "#" + txtImage18_ADD;

            //string savePic1 = string.Empty;
            //foreach (string picUrl in PatHis.Image1_ADD.Split('#'))
            //{
            //    if (string.IsNullOrEmpty(picUrl)) continue;
            //    savePic1 += picUrl + "#";
            //}
            //PatHis.Image1_ADD = savePic1.Trim('#');
            PatHis.Image1_ADD = Request["Image1_ADD"].ToIsNULLString().Replace('|','#');

            string txtImage21_ADD = Request["txtfile21pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage21_ADD"];
            string txtImage22_ADD = Request["txtfile22pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage22_ADD"];
            string txtImage23_ADD = Request["txtfile23pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage23_ADD"];
            string txtImage24_ADD = Request["txtfile24pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage24_ADD"];
            string txtImage25_ADD = Request["txtfile25pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage25_ADD"];
            string txtImage26_ADD = Request["txtfile26pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage26_ADD"];
            string txtImage27_ADD = Request["txtfile27pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage27_ADD"];
            string txtImage28_ADD = Request["txtfile28pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage28_ADD"];
            PatHis.Image2_ADD = txtImage21_ADD + "#" + txtImage22_ADD + "#" + txtImage23_ADD + "#" + txtImage24_ADD + "#" +
                txtImage25_ADD + "#" + txtImage26_ADD + "#" + txtImage27_ADD + "#" + txtImage28_ADD;

            string savePic2 = string.Empty;
            foreach (string picUrl in PatHis.Image2_ADD.Split('#'))
            {
                if (string.IsNullOrEmpty(picUrl)) continue;
                savePic2 += picUrl + "#";
            }
            PatHis.Image2_ADD = savePic2.Trim('#');

            //string txtImage31_ADD = Request["txtfile31pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage31_ADD"];
            //string txtImage32_ADD = Request["txtfile32pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage32_ADD"];
            //string txtImage33_ADD = Request["txtfile33pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage33_ADD"];
            //string txtImage34_ADD = Request["txtfile34pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage34_ADD"];
            //string txtImage35_ADD = Request["txtfile35pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage35_ADD"];
            //string txtImage36_ADD = Request["txtfile36pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage36_ADD"];
            //string txtImage37_ADD = Request["txtfile37pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage37_ADD"];
            //string txtImage38_ADD = Request["txtfile38pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage38_ADD"];
            //PatHis.Image_ADD = txtImage31_ADD + "#" + txtImage32_ADD + "#" + txtImage33_ADD + "#" + txtImage34_ADD + "#" +
            //    txtImage35_ADD + "#" + txtImage36_ADD + "#" + txtImage37_ADD + "#" + txtImage38_ADD;

            //string savePic3 = string.Empty;
            //foreach (string picUrl in PatHis.Image_ADD.Split('#'))
            //{
            //    if (string.IsNullOrEmpty(picUrl)) continue;
            //    savePic3 += picUrl + "#";
            //}
            //PatHis.Image_ADD = savePic3.Trim('#');
            PatHis.Image_ADD = Request["Image_ADD"].ToIsNULLString().Replace('|', '#');

            //string txtImage41_ADD = Request["txtfile41pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage41_ADD"];
            //string txtImage42_ADD = Request["txtfile42pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage42_ADD"];
            //string txtImage43_ADD = Request["txtfile43pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage43_ADD"];
            //string txtImage44_ADD = Request["txtfile44pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage44_ADD"];
            //string txtImage45_ADD = Request["txtfile45pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage45_ADD"];
            //string txtImage46_ADD = Request["txtfile46pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage46_ADD"];
            //string txtImage47_ADD = Request["txtfile47pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage47_ADD"];
            //string txtImage48_ADD = Request["txtfile48pass"].Equals("0") ? string.Empty : dirUrl + Request["txtImage48_ADD"];
            //PatHis.Radiology_HeartSuper_ADD = txtImage41_ADD + "#" + txtImage42_ADD + "#" + txtImage43_ADD + "#" + txtImage44_ADD + "#" +
            //    txtImage45_ADD + "#" + txtImage46_ADD + "#" + txtImage47_ADD + "#" + txtImage48_ADD;

            //string savePic4 = string.Empty;
            //foreach (string picUrl in PatHis.Radiology_HeartSuper_ADD.Split('#'))
            //{
            //    if (string.IsNullOrEmpty(picUrl)) continue;
            //    savePic4 += picUrl + "#";
            //}
            //PatHis.Radiology_HeartSuper_ADD = savePic4.Trim('#');
            PatHis.Radiology_HeartSuper_ADD = Request["Radiology_HeartSuper_ADD"].ToIsNULLString().Replace('|', '#');

            PatHis.Radiology_HeartSuper_Time = Request.Form["txtRadiology_HeartSuper_Time"].ToIsNULLDateTime1(0);
            PatHis.Auxiliary_Tnl_Float = Request.Form["txtAuxiliary_Tnl_Float"].ToDoubleOrNull();
            PatHis.Auxiliary_CKMB_Float = Request.Form["txtAuxiliary_CKMB_Float"].ToDoubleOrNull();
            PatHis.Auxiliary_Myo_Float = Request.Form["txtAuxiliary_Myo_Float"].ToDoubleOrNull();
            PatHis.Auxiliary_Age_Float = Request.Form["txtAuxiliary_Age_Float"].ToDoubleOrNull();
            PatHis.Die_Bool = Request.Form["die_Bool"].ToIsNULLInt(-1);
            if (PatHis.Die_Bool == -1) PatHis.Die_Bool = null;
            PatHis.Medical_DoctorName = Request.Form["txtMedical_DoctorName"].ToIsNULLString();
            PatHis.Diagnosis_Treatment_Style = Request.Form["Diagnosis_Treatment_Style"].ToIsNULLInt(-1);
            if (PatHis.Diagnosis_Treatment_Style == -1) PatHis.Diagnosis_Treatment_Style = null;
            PatHis.Diagnosis_Other_Back = Request.Form["txtDiagnosis_Other_Back"].ToIsNULLString();
            PatHis.Diagnosis_UTreatment_Back = Request.Form["txtDiagnosis_UTreatment_Back"].ToIsNULLString();
            PatHis.IsEcgTransmission = Request.QueryString["LongRange"].ToString();
            PatHis.TransmissionClass = Request.Form["selTransType"] ?? "-1";
            PatHis.TransmissionTime = Request.Form["txtTransTime"].ToIsNULLDateTime1(0);
            PatHis.CardiologistName = Request.Form["txtXnkDoc"].ToString();
            PatHis.ConsultatTime = Request.Form["txtXnkTime"].ToIsNULLDateTime1(0);
            PatHis.StartCatheterTime = Request.Form["txtXnkTime2"].ToIsNULLDateTime1(0);
            PatHis.IsThrombolysis = Request.QueryString["thrombolysis"].ToIsNULLInt();
            PatHis.ThrombolysisAddr = Request.QueryString["thrombolysisAddr"].ToString();
            PatHis.ThrombolysisTime = Request.Form["txtthrombolysisTime"].ToIsNULLDateTime1(0);
            PatHis.ThrombolysisMedicine = Request.Form["txtthrombolysisMedi"].ToIsNULLString();
            PatHis.ThrombolysisDose = Request.Form["txtthrombolysisMetering"].ToIsNULLString();
            PatHis.PatientConsciousness = Request.QueryString["Conscious"].ToString();
            PatHis.PatientBreathe = Request.Form["txtBreath"].ToIntOrNull();
            PatHis.PatientPulse = Request.Form["txtPulse"].ToIntOrNull();
            PatHis.PatientHeart = Request.Form["txtHeartRate"].ToIntOrNull();
            PatHis.PatientBloodH = Request.Form["txtBloodPressure"].ToIntOrNull();
            PatHis.PatientBloodL = Request.Form["txtBloodPressure2"].ToIntOrNull();
            PatHis.DrawBloodTime = Request.Form["txtDrawBloodTime"].ToIsNULLDateTime1(0);
            PatHis.ReportTime = Request.Form["txtReportingTime"].ToIsNULLDateTime1(0);
            PatHis.CtnlValue = Request.Form["txtcTnl"].ToString();
            PatHis.CtnlUnit = Request.Form["selcTnlUnit"] ?? "-1";
            PatHis.CtnlStatus = Request.Form["selcTnlType"].ToIsNULLInt(-1);
            PatHis.CtntValue = Request.Form["txtcTnT"].ToString();
            PatHis.CtntUnit = Request.Form["selcTnTUnit"] ?? "-1";
            PatHis.CtntStatus = Request.Form["selcTnTType"].ToIsNULLInt(-1);
            PatHis.CrValue = Request.Form["txtxqjg"].ToString();
            PatHis.CrUnit = Request.Form["selxqjgUnit"] ?? "-1";
            PatHis.DiagnosticPathId = Request.QueryString["PrelDiagnosis"].ToIsNULLInt();
            string customhtml = Request.Form["ContentList"].ToIsNULLString();
            customhtml = customhtml.Trim('☺');
            string[] list = customhtml.Split('☺');
            List<ChestPainCenterSystem.Model.DiagnosticPathContent> CustomList = new List<ChestPainCenterSystem.Model.DiagnosticPathContent>();
            //ChestPainCenterSystem.Model.DiagnosticPathContent content;
            //foreach (string temp in list)
            //{
            //    string[] control = temp.Split('¤');
            //    if (control != null && control.Length >= 2)
            //    {
            //        content = new ChestPainCenterSystem.Model.DiagnosticPathContent();
            //        content.ControlId = control[0];
            //        content.ControlContent = control[1];
            //        content.ControlType = control[2].ToIsNULLInt();
            //        content.ControlWidth = control[3].ToIsNULLInt();
            //        content.ControlTitle = control[4];
            //        content.ControlName = control[5];
            //        content.ControlDescribe = control[6];
            //        content.Options = control[7];
            //        content.TimeFormart = control[8];
            //        CustomList.Add(content);
            //    }
            //}
            string JsonDiagnosticPathContent = Request.Form["ContentList"].ToIsNULLString();
            if (JsonDiagnosticPathContent != "")
            {
                CustomList = JsonConvert.DeserializeObject<List<ChestPainCenterSystem.Model.DiagnosticPathContent>>(JsonDiagnosticPathContent);
            }

            PatHis.ContentList = CustomList;
            PatHis.LeaveHospitalTime = Request.Form["txtLeaveHospitalTime"].ToIsNULLDateTime1(0);
            PatHis.TreatmentResultType = Request.QueryString["Treatment"].ToIsNULLInt();
            PatHis.TakeMedicineType = Request.Form["TakeMedicineType"].ToIsNULLString();//多选，string
            PatHis.LeaveDoorTime = Request.Form["txtlkbydmsj"].ToIsNULLDateTime1(0);
            PatHis.TransferHospitalName = Request.Form["txtzwyy"].ToIsNULLString();
            PatHis.TransferArriveTime = Request.Form["txtzdsj"].ToIsNULLDateTime1(0);
            PatHis.TransferReason = Request.Form["txtReason"].ToIsNULLString();
            PatHis.IsPCI = Request.QueryString["YzPCI"].ToIsNULLInt();
            PatHis.IsDirectCatheter = Request.QueryString["Zddgs"].ToIsNULLInt();
            PatHis.TransferDepTime = Request.Form["txtZksj"].ToIsNULLDateTime1(0);
            PatHis.ReceptionTime = Request.Form["txtJzsj"].ToIsNULLDateTime1(0);
            PatHis.TransferDepReason = Request.Form["txtZkyyms"].ToIsNULLString();
            PatHis.DieTime = Request.Form["txtDeadTime"].ToIsNULLDateTime1(0);
            PatHis.IsCardiogenic = Request.QueryString["Sfxyx"].ToIsNULLInt();
            PatHis.DieDescribe = Request.Form["txtDeadDescription"].ToIsNULLString();
            PatHis.UpdateUserId = loginUser.Personnel_id;

            PatHis.Killip_LV = Request.Form["rdoKillip_LV"].ToIsNULLInt(-1);
            if (PatHis.Killip_LV == -1) PatHis.Killip_LV = null;
            PatHis.NYHA_LV = Request.Form["rdoNYHA_LV"].ToIsNULLInt(-1);
            if (PatHis.NYHA_LV == -1) PatHis.NYHA_LV = null;
            PatHis.NYHA_Type = Request.Form["chkNYHA_Type"].ToIsNULLString();
            PatHis.STEMI_Methods = Request.Form["chkSTEMI_Methods"].ToIsNULLString();
            PatHis.NSTE_ACS = Request.Form["chkNSTE_ACS"].ToIsNULLString();
            PatHis.PCI_Time = Request.Form["txtPCI_Time"].ToIsNULLDateTime1(0);
            PatHis.Antiplatelet_Time = Request.Form["txtAntiplatelet_Time"].ToIsNULLDateTime1(0);
            PatHis.Antiplatelet_Aspirin = Request["txtAntiplatelet_Aspirin"].ToIsNULLDouble();
            if (PatHis.Antiplatelet_Aspirin == 0) PatHis.Antiplatelet_Aspirin = null;
            PatHis.Antiplatelet_Ticagrelor = Request["txtAntiplatelet_Ticagrelor"].ToIsNULLDouble();
            if (PatHis.Antiplatelet_Ticagrelor == 0) PatHis.Antiplatelet_Ticagrelor = null;
            PatHis.Antiplatelet_Clopidogrel = Request["txtAntiplatelet_Clopidogrel"].ToIsNULLDouble();
            if (PatHis.Antiplatelet_Clopidogrel == 0) PatHis.Antiplatelet_Clopidogrel = null;
            PatHis.Treatment_24H_Bool = Request.Form["rdoTreatment_24H_Bool"].ToIsNULLInt(-1);
            if (PatHis.Treatment_24H_Bool == -1) PatHis.Treatment_24H_Bool = null;
            PatHis.Treatment_Blockers_Bool = Request.Form["rdoTreatment_Blockers_Bool"].ToIsNULLInt(-1);
            if (PatHis.Treatment_Blockers_Bool == -1) PatHis.Treatment_Blockers_Bool = null;
            PatHis.Visit_ECG_Time = Request.Form["txtVisit_ECG_Time"].ToIsNULLDateTime1(0);
            PatHis.Visit_Troponin_STime = Request.Form["txtVisit_Troponin_STime"].ToIsNULLDateTime1(0);
            PatHis.Visit_Troponin_RTime = Request.Form["txtVisit_Troponin_RTime"].ToIsNULLDateTime1(0);
            PatHis.Visit_Troponin_Result = Request.Form["txtVisit_Troponin_Result"].ToIsNULLDouble();
            if (PatHis.Visit_Troponin_Result == 0) PatHis.Visit_Troponin_Result = null;
            PatHis.Grace_Risk_LV = Request.Form["chkGrace_Risk_LV"].ToIsNULLString();
            PatHis.Grace_Risk_Type = Request.Form["chkGrace_Risk_Type"].ToIsNULLString();
            PatHis.Visit_Diagnosis = Request.Form["rdoVisit_Diagnosis"].ToIsNULLInt(-1);
            if (PatHis.Visit_Diagnosis == -1) PatHis.Visit_Diagnosis = null;
            PatHis.Visit_Diagnosis_Time = Request.Form["txtVisit_Diagnosis_Time"].ToIsNULLDateTime1(0);

            PatHis.Hospital_ID = Request.Form["Hospital_ID"].ToIsNULLString();
            PatHis.HelpTime = Request.Form["HelpTime"].ToIsNULLDateTime1(0);
            PatHis.OutComeType = Request.Form["OutComeType"].ToIntOrNull();
            PatHis.Patient_National = Request.Form["Patient_NationalID"].ToIsNULLString();
            PatHis.PATIENT_SPO2 = Request.Form["PATIENT_SPO2"].ToIntOrNull();

            PatHis.Patient_Pay_Type = Request.Form["Patient_Pay_Type_Ex"].ToIntOrNull();
            PatHis.PATIENT_ADDR_Province = Request.Form["PATIENT_ADDR_Province_Ex"].ToIsNULLString();
            PatHis.PATIENT_ADDR_City = Request.Form["PATIENT_ADDR_City_Ex"].ToIsNULLString();
            PatHis.PATIENT_ADDR_District = Request.Form["PATIENT_ADDR_District_Ex"].ToIsNULLString();
            PatHis.ECG_CONFIRM_TIME = Request.Form["ECG_CONFIRM_TIME_Ex"].ToIsNULLDateTime1(0);
            PatHis.AspirinClopidogrel_Bool = Request.Form["AspirinClopidogrel_Bool_Ex"].ToIsNULLInt(-1);
            PatHis.Thrombolysis_Check = Request.Form["Thrombolysis_Check_Ex"].ToIsNULLInt(-1);
            PatHis.Thrombolysis_Surgery = Request.Form["Thrombolysis_Surgery_Ex"].ToIsNULLInt(-1);
            PatHis.Thrombolysis_Place = Request.Form["Thrombolysis_Place_Ex"].ToIsNULLInt(-1);
            PatHis.Thrombolysis_Agree_Time = Request.Form["Thrombolysis_Agree_Time_Ex"].ToIsNULLDateTime1(0);
            PatHis.Thrombolysis_UnderstandAgree_Time = Request.Form["Thrombolysis_UnderstandAgree_Time_Ex"].ToIsNULLDateTime1(0);
            PatHis.Thrombolysis_Start_Time = Request.Form["Thrombolysis_Start_Time_Ex"].ToIsNULLDateTime1(0);
            PatHis.Thrombolysis_End_Time = Request.Form["Thrombolysis_End_Time_Ex"].ToIsNULLDateTime1(0);
            PatHis.Thrombolysis_Imaging_Time = Request.Form["Thrombolysis_Imaging_Time_Ex"].ToIsNULLDateTime1(0);
            PatHis.Thrombolysis_Drug_Type = Request.Form["Thrombolysis_Drug_Type_Ex"].ToIntOrNull();
            PatHis.Thrombolysis_Drug_Dose = Request.Form["Thrombolysis_Drug_Dose_Ex"].ToIntOrNull();
            PatHis.Thrombolysis_Recanalization_Bool = Request.Form["Thrombolysis_Recanalization_Bool_Ex"].ToIntOrNull();
            PatHis.PreHospital_Diagnosis = Request.Form["PreHospital_Diagnosis_Ex"].ToIntOrNull();
            PatHis.PreHospital_CPC = Request.Form["PreHospital_CPC_Ex"].ToIntOrNull();
            PatHis.Triage_To = Request.Form["Triage_To_Ex"].ToIntOrNull();
            PatHis.Troponin_Num = Request.Form["Troponin_Num_Ex"].ToDoubleOrNull();
            PatHis.Check_D_Dimer = Request.Form["Check_D_Dimer_Ex"].ToDoubleOrNull();
            PatHis.Check_BNPNT = Request.Form["Check_BNPNT_Ex"].ToDoubleOrNull();
            PatHis.Check_D_Dimer_Unit = Request.Form["Check_D_Dimer_Unit_Ex"].ToIntOrNull();
            PatHis.CT_NoticeTime = Request.Form["CT_NoticeTime_Ex"].ToIsNULLDateTime1(0);
            PatHis.EnhancedCT_STime = Request.Form["EnhancedCT_STime_Ex"].ToIsNULLDateTime1(0);
            PatHis.IS_NOTICE_IMCD = Request.Form["IS_NOTICE_IMCD_Ex"].ToIntOrNull();
            PatHis.Cardiology_Consultation_Time = Request.Form["Cardiology_Consultation_Time_Ex"].ToIsNULLDateTime1(0);
            PatHis.Catheter_Start_Type = Request.Form["Catheter_Start_Type_Ex"].ToIntOrNull();
            PatHis.Catheter_Start_Doctor = Request.Form["Catheter_Start_Doctor_Ex"].ToIsNULLString();
            PatHis.Catheter_Vascular_Pathway = Request.Form["Catheter_Vascular_Pathway_Ex"].ToIntOrNull();
            PatHis.Catheter_CulpritVessel_Type = Request.Form["Catheter_CulpritVessel_Type_Ex"].ToIntOrNull();
            PatHis.Catheter_CulpritVessel_Location = Request.Form["Catheter_CulpritVessel_Location_Ex"].ToIsNULLString();
            PatHis.Catheter_NoCulpritVessel_Type = Request.Form["Catheter_NoCulpritVessel_Type_Ex"].ToIntOrNull();
            PatHis.Catheter_NoCulpritVessel_Location = Request.Form["Catheter_NoCulpritVessel_Location_Ex"].ToIsNULLString();
            PatHis.Catheter_BloodClots_Bool = Request.Form["Catheter_BloodClots_Bool_Ex"].ToIntOrNull();
            PatHis.Catheter_Lesions_Bool = Request.Form["Catheter_Lesions_Bool_Ex"].ToIntOrNull();
            PatHis.Catheter_CTO_Bool = Request.Form["Catheter_CTO_Bool_Ex"].ToIntOrNull();
            PatHis.Catheter_Stents_Num = Request.Form["Catheter_Stents_Num_Ex"].ToIntOrNull();
            PatHis.Catheter_Anticoagulation_Type = Request.Form["Catheter_Anticoagulation_Type_Ex"].ToIntOrNull();
            PatHis.Catheter_Anticoagulation_Num = Request.Form["Catheter_Anticoagulation_Num_Ex"].ToDoubleOrNull();
            PatHis.Catheter_Anticoagulation_Time = Request.Form["Catheter_Anticoagulation_Time_Ex"].ToIsNULLDateTime1(0);
            PatHis.Catheter_Imaging_Lumen = Request.Form["Catheter_Imaging_Lumen_Ex"].ToIntOrNull();
            PatHis.Catheter_Detection_Type = Request.Form["Catheter_Detection_Type_Ex"].ToIntOrNull();
            PatHis.Catheter_IABP_Bool = Request.Form["Catheter_IABP_Bool_Ex"].ToIntOrNull();
            PatHis.Catheter_BloodClots_Suction = Request.Form["Catheter_BloodClots_Suction_Ex"].ToIntOrNull();
            PatHis.Catheter_Pacemaker = Request.Form["Catheter_Pacemaker_Ex"].ToIntOrNull();
            PatHis.Catheter_ECMO = Request.Form["Catheter_ECMO_Ex"].ToIntOrNull();
            PatHis.Catheter_LeftAssistDevice = Request.Form["Catheter_LeftAssistDevice_Ex"].ToIntOrNull();
            PatHis.Catheter_Complications = Request.Form["Catheter_Complications_Ex"].ToIsNULLString();
            PatHis.OutCome_DIAGNOSIS = Request.Form["OutCome_DIAGNOSIS_Ex"].ToIntOrNull();
            PatHis.OutCome_Time = Request.Form["OutCome_Time_Ex"].ToIsNULLDateTime1(0);
            PatHis.OutCome_72H_MAX = Request.Form["OutCome_72H_MAX_Ex"].ToDoubleOrNull();
            PatHis.OutCome_BNP_Type = Request.Form["OutCome_BNP_Type_Ex"].ToIntOrNull();
            PatHis.OutCome_BNP_Values = Request.Form["OutCome_BNP_Values_Ex"].ToDoubleOrNull();
            PatHis.OutCome_Imaging = Request.Form["OutCome_Imaging_Ex"].ToDoubleOrNull();
            PatHis.OutCome_Complications = Request.Form["OutCome_Complications_Ex"].ToIsNULLString();
            PatHis.OutCome_Risk = Request.Form["OutCome_Risk_Ex"].ToIsNULLString();
            PatHis.OutCome_HeartFailure = Request.Form["OutCome_HeartFailure_Ex"].ToIntOrNull();
            PatHis.InHospital_Day = Request.Form["InHospital_Day_Ex"].ToIntOrNull();
            PatHis.OutCome_Cost = Request.Form["OutCome_Cost_Ex"].ToIntOrNull();
            PatHis.Treatment_Results = Request.Form["Treatment_Results_Ex"].ToIntOrNull();

            string Json = JsonConvert.SerializeObject(PatHis);
            OperateResult resultInfo2 = MedicalRecordsManager.SetCaseHistory(Json);
            if (resultInfo2.Result == 1)
            {
                ConfigurationManager.RefreshSection("appSettings");
                string picVirPath = ConfigurationManager.AppSettings["ImageUploadPath"].ToString();
                if (!string.IsNullOrWhiteSpace(Image1_ADD_Old) && !string.IsNullOrWhiteSpace(PatHis.Image1_ADD) && !Image1_ADD_Old.Equals(PatHis.Image1_ADD) && Image1_ADD_Old.IndexOf("#") < 0)
                    System.IO.File.Delete(Server.MapPath(picVirPath + Image1_ADD_Old));
                if (!string.IsNullOrWhiteSpace(Image2_ADD_Old) && !string.IsNullOrWhiteSpace(PatHis.Image2_ADD) && !Image2_ADD_Old.Equals(PatHis.Image2_ADD) && Image2_ADD_Old.IndexOf("#") < 0)
                    System.IO.File.Delete(Server.MapPath(picVirPath + Image2_ADD_Old));
                if (!string.IsNullOrWhiteSpace(Image_ADD_Old) && !string.IsNullOrWhiteSpace(PatHis.Image_ADD) && !Image_ADD_Old.Equals(PatHis.Image_ADD) && Image_ADD_Old.IndexOf("#") < 0)
                    System.IO.File.Delete(Server.MapPath(picVirPath + Image_ADD_Old));
            }
            return Content(resultInfo2.Body.ToString());
        }

        /// <summary>
        /// 检测图片文件名
        /// </summary>
        /// <param name="picName"></param>
        /// <returns></returns>
        public bool CheckPicName(string picName)
        {
            if (string.IsNullOrWhiteSpace(picName)) return false;
            if (picName.IndexOf(".") <= 0) return false;
            string[] picNameArr = picName.Split('.');
            if (picNameArr.Length < 2) return false;
            string ext = picNameArr[picNameArr.Length - 1];
            ext = ext.ToLower();
            if (ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "gif" || ext == "bmp")
                return true;
            return false;
        }

        /// <summary>
        /// 打印报表
        /// </summary>
        /// <returns></returns>
        public ActionResult EventPrint()
        {
            string pid = WebUtils.GetString("pid");
            if (string.IsNullOrWhiteSpace(pid))
                return Content("缺少ID参数");
            ViewBag.pid = pid;
            return View();
        }
        /// <summary>
        /// 打印报表 泉一新
        /// </summary>
        /// <returns></returns>
        public ActionResult EventPrintPlus()
        {
            string pid = WebUtils.GetString("pid");
            if (string.IsNullOrWhiteSpace(pid))
                return Content("缺少ID参数");
            ViewBag.pid = pid;
            return View();
        }
        /// <summary>
        /// 获取科室下拉列表
        /// </summary>
        /// <returns></returns>
        public ActionResult GetDropRoomList()
        {
            string key = Request["key"];
            string list = Request["list"];
            if (!string.IsNullOrEmpty(list))
                return JsonDate(GetCheckDropList(list, key));
            OperateResult result = MedicalRecordsManager.GetDepartmentName();
            if (result.Result == 1)
            {
                ViewBag.RoomList = JsonConvert.SerializeObject(result.Body);
                return JsonDate(result.Body);
            }
            return Content("");
        }
        /// <summary>
        /// 获取医生和护士综合下拉列表
        /// </summary>
        /// <returns></returns>
        public ActionResult GetDropDocNurList()
        {
            string key = Request["key"];
            string list = Request["list"];
            if (!string.IsNullOrEmpty(list))
                return JsonDate(GetCheckDropList(list, key));
            OperateResult result = MedicalRecordsManager.GetUserName(string.Empty);
            if (result.Result == 1)
            {
                ViewBag.DocNurList = JsonConvert.SerializeObject(result.Body);
                return JsonDate(result.Body);
            }
            return Content("");
        }
        /// <summary>
        /// 获取医生下拉列表
        /// </summary>
        /// <returns></returns>
        public ActionResult GetDropDoctorList()
        {
            string key = Request["key"];
            string list = Request["list"];
            if (!string.IsNullOrEmpty(list))
                return JsonDate(GetCheckDropList(list, key));
            OperateResult result = MedicalRecordsManager.GetUserName("医生");
            if (result.Result == 1)
            {
                ViewBag.DoctorList = JsonConvert.SerializeObject(result.Body);
                return JsonDate(result.Body);
            }
            return Content("");
        }
        /// <summary>
        /// 获取护士下拉列表
        /// </summary>
        /// <returns></returns>
        public ActionResult GetDropNurseList()
        {
            string key = Request["key"];
            string list = Request["list"];
            if (!string.IsNullOrEmpty(list))
                return JsonDate(GetCheckDropList(list, key));
            OperateResult result = MedicalRecordsManager.GetUserName("护士");
            if (result.Result == 1)
            {
                ViewBag.NurseList = JsonConvert.SerializeObject(result.Body);
                return JsonDate(result.Body);
            }
            return Content("");
        }
        /// <summary>
        /// 动态加载下拉列表 实时搜索
        /// </summary>
        /// <param name="list">源数据</param>
        /// <param name="key">搜索值</param>
        /// <returns></returns>
        private List<DropItem> GetCheckDropList(string list, string key)
        {
            if (string.IsNullOrEmpty(list))
                return new List<DropItem>();
            var doctorlist2 = JsonConvert.DeserializeObject<List<DropItem>>(HttpUtility.UrlDecode(list));
            if (!string.IsNullOrEmpty(key))
                return doctorlist2.Where(p => p.Name.Contains(key)).ToList();
            return doctorlist2;
        }

        /// <summary>
        /// 获取导航列表
        /// </summary>
        /// <returns></returns>
        public ActionResult getNavList()
        {
            OperateResult result = MedicalRecordSetManager.GetMedicalConfig(1);
            return JsonDate(result);
        }
    }
    public class DropItem
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
}